package com.icoolkj.learn.juc.base;

import lombok.extern.slf4j.Slf4j;

/**
 * @author icoolkj
 * @version 1.0
 * @description 实现 t1 t2 t3 三个线程按照顺序执行
 * @createDate 2025/03/04 12:53
 */
@Slf4j
public class ThreadJoinDemo2 {

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
           log.info("t1 is running");
        },"t1");

        Thread t2 = new Thread(() -> {
            try {
                t1.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            log.info("t2 is running");
        },"t2");

        Thread t3 = new Thread(() -> {
            try {
                t2.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            log.info("t3 is running");
        },"t3");

        t1.start();
        t2.start();
        t3.start();
    }
}
